home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Qpopper / pop_uidl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-01  |  4.6 KB  |  181 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/file.h>
  4. #include <sys/wait.h>
  5. #include <ctype.h>
  6.  
  7. #if defined(SOLARIS2) || defined(SYSV) || defined(AIX)
  8. #include <string.h>
  9. #ifndef index
  10. # define index(s,c)        strchr(s,c)
  11. #endif
  12. #else
  13. #include <strings.h>
  14. #endif
  15.  
  16. #include "popper.h"
  17.  
  18. /*
  19.  *  uidl:   POP UIDL function to list messages by message-ids
  20.  */
  21.  
  22. pop_uidl (p)
  23. POP     *   p;
  24. {
  25.     char                    buffer[MAXLINELEN];     /*  Read buffer */
  26.     char            *nl, *bp;
  27.     MsgInfoList         *   mp;         /*  Pointer to message info list */
  28.     int msg_id = 0, x;
  29.     int len = 0;
  30.  
  31.     if (p->parm_count == 1) {
  32.       len = strlen(p->pop_parm[1]);
  33.  
  34.       /*  Convert the parameter into an integer */
  35.       msg_id = atoi(p->pop_parm[1]);
  36.     }
  37.  
  38.     /*  Is requested message out of range? */
  39.     if (len > 0 && msg_id == 0)
  40.     {
  41.       return (pop_msg (p,POP_FAILURE,"Parameter must be a number (range 1 to %d)", p->msg_count));
  42.     }
  43.  
  44.     if (len > 0 && (msg_id < 1 || msg_id > p->msg_count))
  45.       return (pop_msg (p,POP_FAILURE,
  46.           "Message out of range.  %d messages in mail drop.",p->msg_count));
  47.  
  48.     if (msg_id > 0) {
  49.       /*  Get a pointer to the message in the message list */
  50.       mp = &p->mlp[msg_id-1];
  51.  
  52.       if (mp->del_flag) {
  53.         return (pop_msg (p,POP_FAILURE,
  54.                 "Message %d has been marked for deletion.",msg_id));
  55.       } else {
  56.  
  57.     sprintf(buffer, "%d %s", msg_id, mp->uidl_str);
  58.         if (nl = index(buffer, NEWLINE)) *nl = 0;
  59.     return (pop_msg (p,POP_SUCCESS, buffer));
  60.       }
  61.     } else {
  62.     /* yes, we can do this */
  63.     pop_msg (p,POP_SUCCESS,"uidl command accepted.");
  64.  
  65.     for (x = 1; x <= p->msg_count; x++)
  66.     {
  67.         /*  Get a pointer to the message in the message list */
  68.         mp = &p->mlp[x-1];
  69.  
  70.         /*  Is the message flagged for deletion? */
  71.         if (mp->del_flag) continue;
  72.  
  73.         sprintf(buffer, "%d %s", x, mp->uidl_str);
  74. /*        nl = index(mp->uidl_str, NEWLINE); */
  75.         pop_sendline(p, buffer);
  76. /*
  77.         if (!nl)
  78.         fprintf(p->output, "\n");
  79. */
  80.         }
  81.     }
  82.  
  83.     /*  "." signals the end of a multi-line transmission */
  84.     (void)fputs(".\r\n",p->output);
  85.     (void)fflush(p->output);
  86.  
  87.     return(POP_SUCCESS);
  88. }
  89.  
  90. /*
  91.  *  euidl:   POP EUIDL function to list messages by message-ids and adds
  92.  *         message size and From: header text as well.  This is to help
  93.  *         the Newton do some pre-filtering before downloading messages.
  94.  */
  95.  
  96. char *
  97. from_hdr(p, mp)
  98.      POP         *p;
  99.      MsgInfoList *mp;
  100. {
  101.   char buf[MAXLINELEN], *cp;
  102.  
  103.     fseek(p->drop, mp->offset, 0);
  104.     while (fgets(buf, sizeof(buf), p->drop) != NULL) {
  105.       if (buf[0] == '\n') break;    /* From header not found */
  106.       if (!strncasecmp("From:", buf, 5)) {
  107.     cp = index(buf, ':');
  108.     while (*++cp && (*cp == ' ' || *cp == '\t'));
  109.     return(cp);
  110.       }
  111.     }
  112.     return("");
  113. }
  114.  
  115. pop_euidl (p)
  116. POP     *   p;
  117. {
  118.     char                    buffer[MAXLINELEN];     /*  Read buffer */
  119.     char            *nl, *bp;
  120.     MsgInfoList         *   mp;         /*  Pointer to message info list */
  121.     int msg_id = 0, x;
  122.     int len = 0;
  123.  
  124.     if (p->parm_count == 1) {
  125.       len = strlen(p->pop_parm[1]);
  126.  
  127.       /*  Convert the parameter into an integer */
  128.       msg_id = atoi(p->pop_parm[1]);
  129.     }
  130.  
  131.     /*  Is requested message out of range? */
  132.     if (len > 0 && msg_id == 0)
  133.     {
  134.       return (pop_msg (p,POP_FAILURE,"Parameter must be a number (range 1 to %d)", p->msg_count));
  135.     }
  136.  
  137.     if (len > 0 && (msg_id < 1 || msg_id > p->msg_count))
  138.       return (pop_msg (p,POP_FAILURE,
  139.           "Message out of range.  %d messages in mail drop.",p->msg_count));
  140.  
  141.     if (msg_id > 0) {
  142.       /*  Get a pointer to the message in the message list */
  143.       mp = &p->mlp[msg_id-1];
  144.  
  145.       if (mp->del_flag) {
  146.         return (pop_msg (p,POP_FAILURE,
  147.                 "Message %d has been marked for deletion.",msg_id));
  148.       } else {
  149.  
  150.     sprintf(buffer, "%d %s", msg_id, mp->uidl_str);
  151.         if (nl = index(buffer, NEWLINE)) *nl = 0;
  152.     sprintf(buffer, "%s %d %s", buffer, mp->length, from_hdr(p, mp));
  153.     return (pop_msg (p,POP_SUCCESS, buffer));
  154.       }
  155.     } else {
  156.     /* yes, we can do this */
  157.     pop_msg (p,POP_SUCCESS,"uidl command accepted.");
  158.  
  159.     for (x = 1; x <= p->msg_count; x++)
  160.     {
  161.         /*  Get a pointer to the message in the message list */
  162.         mp = &p->mlp[x-1];
  163.  
  164.         /*  Is the message flagged for deletion? */
  165.         if (mp->del_flag) continue;
  166.  
  167.         sprintf(buffer, "%d %s", x, mp->uidl_str);
  168.         if (nl = index(buffer, NEWLINE)) *nl = 0;        
  169.         sprintf(buffer, "%s %d %s", buffer, mp->length, from_hdr(p, mp));
  170.         pop_sendline(p, buffer);
  171.         }
  172.     }
  173.  
  174.     /*  "." signals the end of a multi-line transmission */
  175.     (void)fputs(".\r\n",p->output);
  176.     (void)fflush(p->output);
  177.  
  178.     return(POP_SUCCESS);
  179. }
  180.  
  181.